//
//  AppDelegate.m
//  CWRD
//
//  Created by lanou on 15/9/16.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "AppDelegate.h"
#import "TabBarViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <TencentOpenAPI/TencentOAuth.h>
#import "PlayerDataBase.h"
#import "MineViewController.h"
#import "WXApi.h"
#import "DGAaimaView.h"
#import "CoreStatus.h"
#import "CALayer+Transition.h"
#import "ZWIntroductionViewController.h"

@interface AppDelegate ()<CoreStatusProtocol>
@property(nonatomic,assign) NSInteger time;
@property (nonatomic, strong) ZWIntroductionViewController *introductionView;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //状态栏颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    //////
    TabBarViewController *tabBarVC = [[TabBarViewController alloc]init];
    
    
    TabBarViewController *tabVC = [[TabBarViewController alloc] init];
    MineViewController *mine = [[MineViewController alloc] init];
    
    
    //抽屉视图
    self.deck = [[IIViewDeckController alloc] initWithCenterViewController:tabVC leftViewController:mine];
    self.deck.leftSize = kWidth * 2 / 3;
    self.window.rootViewController = self.deck;
    
    
    //    //默认开始是监测的
    //    [CoreStatus beginNotiNetwork:self];
    
    //////
    
    
    //建表
    [[PlayerDataBase shareDataBase] createCollectList];
    
    
    //ShareSDK
    [ShareSDK registerApp:@"aa3dfa50e988"];
    
    //分享到QQ
    [ShareSDK connectQQWithQZoneAppKey:@"1104803445" qqApiInterfaceCls:[QQApiInterface class] tencentOAuthCls:[TencentOAuth class]];
    
    
    //分享到微信
    //微信收藏
    [ShareSDK connectWeChatFavWithAppId:@"wxc00186175695ce66" appSecret:@"61276f14fbb8c94f49bbb15b3e58f230" wechatCls:[WXApi class]];
    //微信好友
    [ShareSDK connectWeChatSessionWithAppId:@"wxc00186175695ce66" appSecret:@"61276f14fbb8c94f49bbb15b3e58f230" wechatCls:[WXApi class]];
    //微信朋友圈
    [ShareSDK connectWeChatTimelineWithAppId:@"wxc00186175695ce66" appSecret:@"61276f14fbb8c94f49bbb15b3e58f230" wechatCls:[WXApi class]];
    
    
    //判断是否是第一次进入程序,决定是否加载引导页
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    if ([userDefaults objectForKey:@"times"] == nil) {
        //引导动画
        NSArray *coverImageNames = @[@"img_index_01txt", @"img_index_02txt", @"img_index_03txt"];
        NSArray *backgroundImageNames = @[@"img_index_01bg", @"img_index_02bg", @"img_index_03bg"];
        self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
        self.window.rootViewController = self.introductionView;
        
        __weak AppDelegate *weakSelf = self;
        self.introductionView.didSelectedEnter = ^() {
            [weakSelf.introductionView.view removeFromSuperview];
            //        weakSelf.introductionView = nil;
            [weakSelf.introductionView removeFromParentViewController];
            weakSelf.window.rootViewController = weakSelf.deck;
            
        };
    }else {
        [self.introductionView removeFromParentViewController];
    }
    //
    NSUserDefaults *userdefault = [NSUserDefaults standardUserDefaults];
    NSLog(@"++++%ld", [[userdefault objectForKey:@"ONOFF"] integerValue]);
    if ([[userdefault objectForKey:@"ONOFF"] integerValue] == 0) {
        [CoreStatus beginNotiNetwork:self];
    }else {
        [CoreStatus endNotiNetwork:self];
    }
    
    [self.window makeKeyAndVisible];
    return YES;
}




#pragma mark --------------- 流量监测 ----------------

//当网络状态改变的时候被调用
-(void)coreNetworkChangeNoti:(NSNotification *)noti{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"alertView" object:nil];
    
}






- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    // Saves changes in the application's managed object context before the application terminates.
    //    [self saveContext];
}



@end
